<?php
//更新文章时刷新缓存
function baidusu_post_updated($post_ID) {
	$baiduSu = new baiduSu;
	if(!$baiduSu->access_key) return;

	$post_url = get_permalink($post_ID);
	$baiduSu->refresh_cache($post_url);
}
add_action('post_updated', 'baidusu_post_updated', 10, 1);


//文章状态变更时刷新缓存
function baidusu_post_change($post_ID) {
	$baiduSu = new baiduSu;
	if(!$baiduSu->access_key) return;

    $baiduSu->refresh_cache('', 'all');
}
add_action('deleted_post', 'baidusu_post_change', 10, 1); //删除文章时
add_action('trashed_post', 'baidusu_post_change', 10, 1); //移除文章到回收站
add_action('untrashed_post', 'baidusu_post_change', 10, 1); //从回收站恢复文章

//删除分类时刷新缓存
function baidusu_delete_term($term, $tt_id, $taxonomy) {
    $baiduSu = new baiduSu;
	if(!$baiduSu->access_key) return;

	$baiduSu->refresh_cache('', 'all');
}
add_action('delete_term', 'baidusu_delete_term', 10, 3);

//发表文章刷新缓存
function baidusu_insert_post($post_ID, $post, $update) {
	if($update || $post->post_status != 'publish') return;

    $baiduSu = new baiduSu;
	if(!$baiduSu->access_key) return;

    $baiduSu->refresh_cache('', 'all');
}
add_action('save_post_post', 'baidusu_insert_post', 10, 3);
?>
